package com.ocom.common.enums;

import com.ocom.common.resp.Kav;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum MachEnum {
    OK("0000", "成功"),

    TIME_ERROR("0002", "时间设置错误"),
    AUTH_ERROR("0003", "参数/权限设置或记录读取失败"),
    PARAMS_ERROR("0004", "参数不匹配或参数错误"),
    USER_FULL("0005", "用户数满"),
    USER_NOT_FIND("0006", "用户未找到"),
    BLACK_LIST("0007", "黑名单卡"),
    NOT_ORDER("0008", "未订餐"),
    NOT_COMPANY("0009", "没有该部门/没有该公司"),
    NOT_USER("000A", "没有该个人"),
    NOT_CARD("000B", "没有该工号"),
    USER_SEND_BEFORE("000C", "该人已发卡"),
    CARD_SEND_BEFORE("000D", "该工号已发卡"),
    CARD_IN_CONTROL("000E", "该卡已发卡/该卡已控"),
    ADMIN_NOT_SIGN("000F", "管理员未登记"),
    ADMIN_SEND_BEFORE("00010", "该管理员卡已发"),
    MEAL_ORDER_BEFORE("00011", "该餐已订"),
    MEAL_ORDER_FULL("00012", "餐已订满"),
    NOT_SEARCH("0013", "没有相关的查询的信息"),
    APPVER_NULL("0014", "没有升级版本的信息"),
    MACH_NOT_MSG("0401", "设备无数据或当前位置无记录"),
    MACH_NOT_EVENT("0501", "设备无事件"),
    MACH_NOT_INFO("0502", "获取设备信息失败"),
    NOT_COMMTIME_COMMMODE("0503", "修改通讯时间或通信协议失败"),
    NOT_APPVER("0504", "更新设备当前版本（设备上报）失败"),
    NOT_ENOUGH("0673", "余额不足"),
    CARD_NOT_EXIST("0155", "校园卡不存在"),
    USER_NOT_ACTIVE("1203", "用户未激活"),
    CARD_EXPIRE("2203", "校园码过期"),
    CARD_FORMAT_ERR("2202", "校园码格式有误"),
    UNABLE_DECODE("2202", "无法解码"),
    PAYING("3001", "支付中"),
    PAY_NOT_EXIST("3001", "消费订单不存在"),
    REFUNDED("3003", "已退款"),
    NOT_INIT_YKM("2001", "初始化健康码数据失败"),
    NOT_INFO_YKM("2002", "获取粤康码规则信息失败"),
    REQUIRED_NULL("2003", "必填参数为空"),
    ERR("2005", "系统异常"),
    SMS_ERR("2006", "发送邀请失败"),
    ADD_PERSON_ERR("2007", "人员处理失败"),

    NOT_MACH("3004", "未找到设备信息"),
    Qr_NOT_Date("3005", "二维码已过期"),
    MACH_NO_ERR("3006", "设备编号错误"),
    Device_Registered_By_User("3007", "设备已被其他用户登记"),
    Qr_NOT("3008", "无效二维码"),
    Device_Registered_Not_Verified("0701", "设备已登记未验证"),
    DeviceNotActive("0700", "未激活"),
    ERROR("0001", "SessionID，JobID错误，未握手，或者超时"),
    FAIL("3015", "失败"),
    WHITENULL("3013", "获取白名单内容为空"),
    CARDSTATERR("3016", "卡状态异常"),
    PAYTYPEERR("30017", "不支持其他的支付类型"),
    ACCOUNT("30018", "账号状态异常");

    private final String key;
    private final String value;

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    MachEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    /**
     * 根据key获取value
     *
     * @param key : 键值key
     * @return String
     */
    public static String getValueByKey(String key) {
        MachEnum[] enums = MachEnum.values();
        for (int i = 0; i < enums.length; i++) {
            if (enums[i].getKey().equals(key)) {
                return enums[i].getValue();
            }
        }
        return "";
    }

    /**
     * 转换为'KAV'列表
     *
     * @return List<Kav>
     */
    public static List<Kav> toKavs() {
        List<Kav> l_kavs = new ArrayList<Kav>();
        MachEnum[] enums = MachEnum.values();
        for (int i = 0; i < enums.length; i++) {
            Kav kav = new Kav();
            kav.setKey(enums[i].getKey().toString());
            kav.setValue(enums[i].getValue());
            l_kavs.add(kav);
        }
        return l_kavs;
    }

    /**
     * 转换为MAP集合
     *
     * @returnMap<String, String>
     */
    public static Map<String, String> toMap() {
        Map<String, String> map = new HashMap<String, String>();
        MachEnum[] enums = MachEnum.values();
        for (int i = 0; i < enums.length; i++) {
            map.put(enums[i].getKey().toString(), enums[i].getValue());
        }
        return map;
    }


}
